package senior.ListExer.Exer1;

import java.util.ArrayList;
import java.util.List;

/**
 * 公司名称，注册地址，电话，经营范围等属性，公司有很多员工（用List存储）
 * @author shkstart
 * @creat 2022-04-13:36
 */
public class Firm {
    private String firmName;
    private String phone;
    private String address;
    private String scope;
    private List list = new ArrayList();

    public Firm() {
    }

    public Firm(String firmName, String phone, String address, String scope) {
        this.firmName = firmName;
        this.phone = phone;
        this.address = address;
        this.scope = scope;
    }

    public String getFirmName() {
        return firmName;
    }

    public void setFirmName(String firmName) {
        this.firmName = firmName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    /**
     * 添加员工a
     * @param employee
     * @return
     */
    public boolean addEmployee(Employee employee){
        if(list.contains(employee)){
            return false;
        }
        return list.add(employee);
    }

    /**
     * 开除员工
     * @param no
     * @return
     */
    public boolean deleteEmployee(String no){
        //匿名对象，感觉不太合理，但是能实现要求，等老刘解惑
        if(list.contains(new Employee(no))){
            list.remove(new Employee(no));
            return true;
        }
        return false;
    }

    /**
     * 展示员工信息
     */
    public void showEmployee(){
        System.out.println("共有" + list.size() + "名员工：");
        for (Object o:list){
            Employee employee = (Employee)o;
            System.out.println(o);
        }
    }

    @Override
    public String toString() {
        return "公司信息：" +
                "\n名称：" + firmName +
                "\n地址：" + address +
                "\n联系电话：" + phone +
                "\n经营范围：" + scope ;
    }
}
